{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['season', 'yr', 'mnth', 'holiday', 'weekday', 'workingday',\n",
      "       'weathersit', 'temp', 'atemp', 'hum', 'windspeed', 'registered'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.metrics import r2_score\n",
    "\n",
    "#1.读取数据\n",
    "data=pd.read_csv('day.csv')\n",
    "#打印前五行数据\n",
    "# print(data.head())\n",
    "\n",
    "#打印出数据的信息\n",
    "# print(data.info())\n",
    "\n",
    "#查看是否有空值\n",
    "# data.isnull().sum()\n",
    "\n",
    "#1.训练数据和测试数据分割\n",
    "train=data[:365]\n",
    "test=data[365:]\n",
    "# print(train)\n",
    "# print(test)\n",
    "\n",
    "train_y=train['cnt']\n",
    "# print(train_y)\n",
    "\n",
    "train_x=train.drop(['cnt','dteday','casual','instant'],axis=1)\n",
    "\n",
    "test_y=test['cnt']\n",
    "test_x=test.drop(['cnt','dteday','casual','instant'],axis=1)\n",
    "\n",
    "#用于显示权重系数对应的特征\n",
    "columns=train_x.columns\n",
    "print(columns)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "g:\\software\\python3.6\\lib\\site-packages\\ipykernel_launcher.py:14: FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead\n",
      "  \n",
      "g:\\software\\python3.6\\lib\\site-packages\\sklearn\\utils\\validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to float64 by StandardScaler.\n",
      "  warnings.warn(msg, DataConversionWarning)\n",
      "g:\\software\\python3.6\\lib\\site-packages\\ipykernel_launcher.py:15: FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead\n",
      "  from ipykernel import kernelapp as app\n"
     ]
    }
   ],
   "source": [
    "#2. 数据预处理\n",
    "\n",
    "#数据标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "#2.1 实例化\n",
    "ss_x=StandardScaler()\n",
    "ss_y=StandardScaler()\n",
    "\n",
    "#2.2 标准化训练fit\n",
    "train_x=ss_x.fit_transform(train_x)\n",
    "test_x=ss_x.transform(test_x)\n",
    "\n",
    "train_y=ss_y.fit_transform(train_y.reshape(-1,1))\n",
    "test_y=ss_y.transform(test_y.reshape(-1,1))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[0.915698500859935]</td>\n",
       "      <td>registered</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[0.21309250467476648]</td>\n",
       "      <td>temp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[0.005051458768169188]</td>\n",
       "      <td>weekday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[0.004501659593009893]</td>\n",
       "      <td>season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.0]</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[-0.010209046188421639]</td>\n",
       "      <td>holiday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[-0.01120425484905807]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[-0.020050435237368797]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.03199215316645441]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[-0.05684972663484561]</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[-0.057782430634533866]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[-0.2713589763486248]</td>\n",
       "      <td>workingday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       coef     columns\n",
       "11      [0.915698500859935]  registered\n",
       "7     [0.21309250467476648]        temp\n",
       "4    [0.005051458768169188]     weekday\n",
       "0    [0.004501659593009893]      season\n",
       "1                     [0.0]          yr\n",
       "3   [-0.010209046188421639]     holiday\n",
       "9    [-0.01120425484905807]         hum\n",
       "6   [-0.020050435237368797]  weathersit\n",
       "10   [-0.03199215316645441]   windspeed\n",
       "2    [-0.05684972663484561]        mnth\n",
       "8   [-0.057782430634533866]       atemp\n",
       "5     [-0.2713589763486248]  workingday"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#3. 模型选择\n",
    "\n",
    "#3.1 使用OLS模型\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "#实例化模型参数\n",
    "lr=LinearRegression()\n",
    "\n",
    "#训练 fit\n",
    "lr.fit(train_x,train_y)\n",
    "\n",
    "#预测\n",
    "predict_train_y=lr.predict(train_x)\n",
    "predict_test_y=lr.predict(test_x)\n",
    "\n",
    "#查看个特征的权重系数，系数的绝对值越大表名该特征的重要性\n",
    "fs=pd.DataFrame({'columns':list(columns),'coef':list(lr.coef_.T)})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is  0.9341091998387404\n",
      "The r2 score of LinearRegression on train is  0.9574064312709555\n"
     ]
    }
   ],
   "source": [
    "#4 模型评估\n",
    "\n",
    "#使用r2_score评价模型在测试集和训练集上的性能\n",
    "print('The r2 score of LinearRegression on test is ',r2_score(test_y,predict_test_y))\n",
    "print('The r2 score of LinearRegression on train is ',r2_score(train_y,predict_train_y))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1ed26774828>"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAFsCAYAAADos0H8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHgNJREFUeJzt3XuUXWWZ5/HvQxIITYQQCBgSJXEJAoJJoIDQcpNwEzFhZrg5gEEDGaFx7OWlAZkeIsvuRtHRxdIWEYXI/TYsUOgW5DIoCpjYkVuEJBCaQHUSwkXCNQnP/HF2pU+SqtSpW+otzvezVq3al3fv/b57n6rf2fu8e5/ITCRJUnk26e8KSJKk9hnSkiQVypCWJKlQhrQkSYUypCVJKpQhLUl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/ZfPPNG95+IwxpSdJ63nzzTSZMmMCiRYvYa6+9OOyww4BaSN95551rAnbFihXMnz+fAw44gK9+9aucffbZHH300RxwwAFrre+hhx7i4IMPZuTI2pc/nXDCCTz11FMbrENm8vWvf53777+fTTbZhOeff54lS5bw/ve/f02Zvffem89//vOsXLmSY445hgkTJjTcxnHjxq0pv9dee7Fo0SJWrFjB7373O4477j/vKn777beB2v3rJ5xwAq2trbzzzjtr3f88ZcqUXg9o8HK3JKkdbZ9JP/vss7zzzjtrPpPOTM4991zmzp3L3LlzWbBgAdOnT2fnnXdmzpw57LHHHpx77rlccMEF662zo1uSBg8ezLvvvrtm/e+88w4AV199NcuWLWPOnDnMnTuX7bfffr2nsB144IHcf//9jB49mlNOOYWf//znDbdxs802WzM8aNAgVq1axbvvvsvw4cPXtG/u3LnMmzcPgC9+8YucddZZPProo/z4xz9eqy5bbLFFw9vtCs+k1bQa7THb2z1rpYFkq6224uKLL2bq1KmcccYZHHHEEfz93/89J510EsOGDeP5559nyJAhrFq1ihEjRnDyySczbNgwrrjiirXWs++++/KlL32J5cuXs+WWW3LjjTcyfnztERxjx45lzpw5HH/88dx6662sXLkSqF0y32677RgyZAj33nsvzz67/jc8Pvvss4wePZrTTz+d119/nT/+8Y89+lx4yy23ZNy4cdx4440cd9xxZCaPPPII48eP59VXX2X06NEAzJo1q5M19Q5DWpIK199vFCdOnMj48eO57rrrOOWUU5g3bx777bcfUOvkddVVV7FgwQK+9rWvsckmmzBkyBB+9KMfrbWOUaNGMXPmTPbbbz9GjRrFnnvuyerVqwE4/fTTmTp1Kvvssw+TJ09ec1Z60kkn8elPf5qWlhYmTJjALrvssl7d7rvvPi666CKGDBnCsGHDunQm3ZGrr76aM844g29+85usXLmSE088kfHjxzNz5kyOO+44Ro8ezaRJk3jmmWd6vK3ORObG+2KqlpaWbOvlJ/U3z6RVqnnz5rHrrrv2dzXUC9o7lhExJzNbGlnez6QlSSqUIS1JUqEMaUkq0Mb8KFJ9ozeOoSEtSYU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o9JR8Fptct/yFq/7QXADcCm/V3m3qx3ScDK4G5dT8Tqnn3VPviMeAqYFh/t6mT9h4FPEXtrOC8atoF1MIJYGh1/BZUx/NDdcueVy33JPDJ/m5LL7f718CSuuN7WzW9w9f8QPhpoN3/BDxete9eYJe6ZT9fvQ4WAJ/r77b0dtur8ZnAhessN2CPObXOb63V/6vF1PpXfAH4QjU/gB9W++RRoOW9cry7++NjQSVJKtRAutwtSVJTMaQlSSqUIS1JUqEMaUmSCmVIS5JUKENakqRCGdKSJBXq/wM698NGzZYWSwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "f,ax=plt.subplots(figsize=(7,5))\n",
    "f.tight_layout()\n",
    "ax.hist(train_y-predict_train_y,bins=40,label='Residuals linear',color='b',alpha=0.5)\n",
    "ax.set_title(\"histogram of Residuals\")\n",
    "ax.legend(loc='best')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl4lOXV+PHvmckkmUAgQEBKQHErlR1BRamKVgtaZasKFn2hWlvfWpeCtLhV6YYtrVLre9FSqHVr3c1PpIoC2rqiIEtExAUFiWwBEgjZJsn5/TETHJLZkszkmcycz3VxmZk88zwHJId7PbeoKsYYkwgupwMwxqQuSzDGmISxBGOMSRhLMMaYhLEEY4xJGEswxpiEsQRjjEkYSzDGmISxBGOMSZgMpwNojvz8fO3bt6/TYRiT9tasWVOiqt2jXdeuEkzfvn1ZvXq102EYk/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hjTMJYgjHGJIwlGGNMwliCMcYkTLteaGecISLdgBWBlz2BOmBP4PWpgb1Gxtg0tWkdEbkLKFfVPzR6X/D//aoP+UGTFqyLZOJGRE4I7Hv6C/Ae0EdESoO+P0VEFgW+PkpEnhGR1YFaJCND3O/N4D0xIrJKRAa0xe/FxIclGBNv/YHFqjoMiLRy+j7g9+o/g+cyYFGIaxYD0wFEpD+Aqm6Ma7QmoWwMxsTbp6r6bgzXnQf08/ekAOgiIl5VrQy65jFgXaD63VXAA/EN1SSaJRgTb4eCvq7nyDIN2UFfC1EGhFX1UGBn7zjgu8DQOMZp2oB1kUzCBAZ494vIiSLiAiYGfXs5cF3DCxEJlzwWAfcDb6pqWcKCNQlhCcYk2s+BF/FPa28Pev86YFSgGPoHwDWhPhyorFaBdY/aJZumNklNRPoALwMnJbpYl4k/a8GYpCUi3wfexF8jxZJLO2QtGGNMwlgLxhiTMJZgjDEJYwnGGJMwlmCMMQljCcYYkzD/H6yDFJd8PM5oAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#通过散点图评价\n",
    "plt.figure(figsize=(4,3))\n",
    "plt.scatter(train_y,predict_train_y)\n",
    "plt.plot([-3,3],[-3,3],'--k')\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True y')\n",
    "plt.ylabel('Predict y ')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is  0.9347351685646996\n",
      "The r2 score of RidgeCV on train is  0.9573540198526015\n"
     ]
    }
   ],
   "source": [
    "# 3.2 岭回归模型\n",
    "from sklearn.linear_model import RidgeCV\n",
    "#设置超参数（正则参数）搜索范围\n",
    "alphas=[0.01,0.1,1,10,100]\n",
    "\n",
    "#实例化\n",
    "ridge=RidgeCV(alphas=alphas,store_cv_values=True)\n",
    "\n",
    "#训练\n",
    "ridge.fit(train_x,train_y)\n",
    "\n",
    "#预测\n",
    "predict_test_y=ridge.predict(test_x)\n",
    "predict_train_y=ridge.predict(train_x)\n",
    "\n",
    "#评估\n",
    "print('The r2 score of RidgeCV on test is ',r2_score(test_y,predict_test_y))\n",
    "print('The r2 score of RidgeCV on train is ',r2_score(train_y,predict_train_y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3X1wHPWd5/H315L14Cf5SbaFbdkGDMRgHmxhSEhYKoSEcCwOAWJbXI7kuHCpK+qyyVXdsrW32Sv+2WKfUrsXtvbIQpZLItvEEGISgiEQ8oweDH7AgEEYPBKyLT9KftLz9/6YHjOMR56RrZ6e0XxeVSr3dP9m+jsteT7T/Z3uMXdHRETkTMZFXYCIiOQ/hYWIiGSksBARkYwUFiIikpHCQkREMlJYiIhIRgoLERHJSGEhIiIZKSxERCSj0qgLGC0zZ870hQsXRl2GiEhB2bx58wF3r840bsyExcKFC2lpaYm6DBGRgmJmu7MZp8NQIiKSkcJCREQyUliIiEhGCgsREclIYSEiIhkpLEREJCOFhYiIZKSwEBEpYN///Xu88Ma+0NejsBARKVBHe/r5u007eeGNvaGvS2EhIlKgnt7SwYm+QeqvWRD6uhQWIiIFyN1paIyxpGYKV8yrCn19CgsRkQK0tb2LN/d0U39NLWYW+voUFiIiBaihcTcTykpYeeV5OVmfwkJEpMB09/TzzNY9rLzyPCZXjM/JOhUWIiIF5unXPuBk/yD1K8JvbCcoLERECkiisb10bhVLc9DYTl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
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alphas is : 1.0\n"
     ]
    }
   ],
   "source": [
    "mse_mean=np.mean(ridge.cv_values_,axis=0)\n",
    "plt.plot(np.log10(alphas),mse_mean.reshape(len(alphas),1))\n",
    "\n",
    "plt.xlabel('Log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alphas is :',ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is  0.9317577533543687\n",
      "The r2 score of LassoCV on train is  0.956426743890004\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "g:\\software\\python3.6\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "# 3.3 Lasso回归\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "alphas=[0.01,0.1,1,10,100]\n",
    "\n",
    "lasso=LassoCV(alphas=alphas)\n",
    "lasso.fit(train_x,train_y)\n",
    "predict_test_y=lasso.predict(test_x)\n",
    "predict_train_y=lasso.predict(train_x)\n",
    "\n",
    "print('The r2 score of LassoCV on test is ',r2_score(test_y,predict_test_y))\n",
    "print('The r2 score of LassoCV on train is ',r2_score(train_y,predict_train_y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yL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fGINc1wAPuvtvX+hniQxF1xREPmkZ8A/BYCcniY/vDYC7v2BmYY+3PJRS4kcRIqHRkYKIiPTTNQUREemnoiAiIv1UFEREpJ+KgoiI9FNREBGRfioKIiLS7/8Dz/nZ/zBTFIEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is :  0.01\n"
     ]
    }
   ],
   "source": [
    "mses=np.mean(lasso.mse_path_,axis=1)\n",
    "plt.plot(np.log10(lasso.alphas_),mses)\n",
    "plt.xlabel('Log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alpha is : ',lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
